﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TravelLib
{

    public class RouteWrapper
    {
        public string DepartureAirportName
        {
            get;
            set;
        }

        public string DestinationAirtportName
        {
            get;
            set;
        }

        public DateTime DteTo
        {
            get;
            set;
        }
        public DateTime DteFrom
        {
            get;
            set;
        }

        public RouteWrapper(Route r)
        {
            DepartureAirportName = r.DepartureAirportName;
            DestinationAirtportName = r.DestinationAirtportName;
            DteTo = r.DteTo;
            DteFrom = r.DteFrom;
        }

        public RouteWrapper()
        {
            // TODO: Complete member initialization
        }
    }


    public class Route
    {
        private string _departureAirportName;

        public string DepartureAirportName
        {
            get
            {
                //if (string.IsNullOrEmpty(_departureAirportName) && null != _departureAirport)
                //    return _departureAirport.Name;
                //else

                    return
                    _departureAirportName;
            }
            set
            {
                _departureAirportName = value;
                this._departureAirport = AirportManager.GetAirportByName(_departureAirportName);
            }
        }
        private Airport _departureAirport;

        public Airport DepartureAirport
        {
            get
            {
                //if (null == _departureAirport && !string.IsNullOrEmpty(_departureAirportName))
                //    return AirportManager.GetAirportByName(_departureAirportName);
                return _departureAirport;
            }
            set
            {
                _departureAirport = value;

                _departureAirportName = value.Name;
            }
        }

        private Airport _destinationAirport;

        public Airport DestinationAirport
        {
            get
            {
                //if (null == _destinationAirport && !string.IsNullOrEmpty(_destinationAirtportName))
                //    return AirportManager.GetAirportByName(_destinationAirtportName);

                return
                _destinationAirport;
            }
            set
            {
                _destinationAirport = value;
                //_destinationAirtportName = _destinationAirport.Name;
            }
        }
        private string _destinationAirtportName;

        public string DestinationAirtportName
        {
            get
            {
                if (string.IsNullOrEmpty(_destinationAirtportName) && null != _destinationAirport)
                    return _destinationAirport.Name;
                else
                    return _destinationAirtportName;
            }
            set
            {
                _destinationAirtportName = value;
                this._destinationAirport = AirportManager.GetAirportByName(_destinationAirtportName);
            }
        }

        private DateTime _dteFrom;

        public DateTime DteFrom
        {
            get { return _dteFrom; }
            set { _dteFrom = value; }
        }

        private DateTime _dteTo;

        public DateTime DteTo
        {
            get { return _dteTo; }
            set { _dteTo = value; }
        }

        public Route(string start, string destination, DateTime dtefrom, DateTime dteto)
        {
            this._departureAirportName = start;
            this._destinationAirtportName = destination;

            this._departureAirport = AirportManager.GetAirportByName(start);
            this._destinationAirport = AirportManager.GetAirportByName(destination);

            this._dteFrom = dtefrom;
            this._dteTo = dteto;
        }
        public Route(RouteWrapper r)
        {
            this._departureAirportName = r.DepartureAirportName;
            this._destinationAirtportName = r.DestinationAirtportName;

            this._departureAirport = AirportManager.GetAirportByName(r.DepartureAirportName);
            this._destinationAirport = AirportManager.GetAirportByName(r.DestinationAirtportName);

            this._dteFrom = r.DteFrom;
            this._dteTo = r.DteTo;
        }
        public Route()
        {
            this._departureAirportName = String.Empty;
            this._destinationAirtportName = String.Empty;
            this._departureAirport = null;
            this._destinationAirport = null;
            this._dteFrom = DateTime.Now.Date;
            this._dteTo = DateTime.Now.Date;
        }

        internal bool Includes(Route route)
        {
            bool t = _departureAirportName == route.DepartureAirportName
                && _destinationAirtportName == route.DestinationAirtportName;
                //&& _dteFrom.Date <= route.DteFrom.Date
                //&& DteTo.Date >= route.DteTo.Date;
            return (t);
        }

        internal bool Includes(RouteWrapper route)
        {
            bool t = _departureAirportName == route.DepartureAirportName
                && _destinationAirtportName == route.DestinationAirtportName;
                //&& _dteFrom.Date <= route.DteFrom.Date
                //&& _dteTo.Date >= route.DteTo.Date;
            return (t);
        }
        public bool IsEqual(Route route)
        {
            return (_departureAirportName.CompareTo(route.DepartureAirportName) == 0
                && _destinationAirtportName.CompareTo(route.DestinationAirtportName) == 0
                //&& _dteFrom.CompareTo(route.DteFrom) == 0
                //&& DteTo.CompareTo(route.DteTo) == 0)
                );
        }
    }
}
